<?php
//define("PATH", str_replace("/index.php", "/", $_SERVER['SCRIPT_FILENAME']));
define("PATH", "./");
define("CONFIG_PATH", PATH . "config/");
define("SYSTEM_PATH", PATH . "system/");
define("CORE_PATH", SYSTEM_PATH . "core/");
define("CHAT_PATH", CORE_PATH . "chat/");
define("MAIL_PATH", CORE_PATH . "mail/");
define("STATIC_PATH", SYSTEM_PATH . "static/");
define("HTML_PATH", STATIC_PATH . "html/");
define("LANGUAGE_PATH", STATIC_PATH . "language/");
define("SYSTEM_CONFIG_PATH", STATIC_PATH . "config/");
define("INSTALLER_PATH", CORE_PATH . "installer/");
define("FILE_DB_PATH",SYSTEM_PATH . "data/");

define("XCGZS_SECRET", "xcgzs666");

//语言部分
include(CHAT_PATH . 'cookie.php');
//$language_json = json_decode(file_get_contents(LANGUAGE_PATH . "languages.json"), true);
//$language_list = array();
//for ($i = 1; $i <= count($language_json); $i++) {
//    $a = 'lang' . $i; //语言序列
//    $b = $language_json[$a]; //语言值
//    $c = json_decode(file_get_contents(LANGUAGE_PATH . $b . ".json"), true);//语言列表
//    $d = $c['LANGUAGE_NAME'];//语言名称
//    $language_list[$b] = $d;
//}
//define("LANGUAGE_LIST", $language_json);
//define("LANGUAGE_JSON", $language_list);
//unset($language_list);
//$local_language = cookie::get("local_language");
//if (!$local_language) {
//    $local_language = array_keys(LANGUAGE_JSON)[0];//默认语言,用户没有设置语言时将加载第一个语言
//}
//$language_table = json_decode(file_get_contents(LANGUAGE_PATH . $local_language . ".json"), true);
//for ($i = 0; $i < count($language_table); $i++) {
//    $a = array_keys($language_table)[$i];
//    $b = $language_table[$a];
//    define($a, $b);
//}
$language_json = json_decode(file_get_contents(LANGUAGE_PATH."languages.json"),true);
$language_list = array();
$local_language = cookie::get("local_language") ? cookie::get("local_language") : "zh-cn";
define("LOCAL_LANGUAGE",$local_language);
foreach ($language_json as $item) {
    $language_list[$item] = $l_b = explode("=",explode("\n",str_replace("\n\n","\n",str_replace("\r","\n",file_get_contents(LANGUAGE_PATH . $item . ".lang"))))[0])[1];
}
define("LANGUAGE_LIST",$language_list);
foreach (explode("\n",str_replace("\n\n","\n",str_replace("\r","\n",file_get_contents(LANGUAGE_PATH . $local_language . ".lang")))) as $item) {
    if(!$item && substr($item,0,1)=="#"){
        break;
    }
    $a = explode("=",$item);
    define($a[0],$a[1]);
//    echo $a[0] . " = " . $a[1] . "<br>";
    unset($item);
}